﻿using System.IO;
using System.Xml.Serialization;

namespace TradeMo
{
    public static class ObjectExtensions
    {
        public static T Clone<T>(this T source)
        {
            if (ReferenceEquals(source, null)) return default(T);

            var transform = new XmlSerializer(typeof (T));
            using(Stream stream = new MemoryStream())
            {
                transform.Serialize(stream, source);

                stream.Seek(0, SeekOrigin.Begin);
                return (T)transform.Deserialize(stream);
            }
        }
    }
}
